package com.varian.system.vo;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.varian.system.enums.DictValueTypeEnum;
import com.varian.tool.enums.CommonStatusEnum;
import com.varian.tool.model.BaseVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @author ben
 * @since 2024/7/9
 */
@Data
@Schema(title = "字典视图对象")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SysDictVO extends BaseVO {
    @Schema(title = "上级字典id")
    private Long parentId;
    @Schema(title = "字典名称")
    private String dictName;
    @Schema(title = "字典编码")
    private String dictCode;
    @Schema(title = "字典值")
    private String dictValue;
    @Schema(title = "字典类型")
    private DictValueTypeEnum dictValueType;
    @Schema(title = "字典渲染类型")
    private String dictRenderType;
    @Schema(title = "字典描述")
    private String dictDesc;
    @Schema(title = "权重")
    private Integer dictWeight;
    @Schema(title = "字典状态")
    private CommonStatusEnum dictStatus;
    @Schema(title = "是否为默认项")
    private Boolean defaultItem;
    @Schema(title = "创建时间")
    private LocalDateTime createTime;

    public Object getDictValue() {
        if (StrUtil.isNotEmpty(dictValue)) {
            return dictValueType.equals(DictValueTypeEnum.NUMBER) ? Integer.parseInt(dictValue) : dictValue;
        }
        return null;
    }
}
